package com.example.springfox.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.springfox.entity.ResponseData;
import com.example.springfox.entity.User;
import com.example.springfox.util.EnumCode;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hett
 * @date: 2022/1/17 10:01
 */
@ApiResponses({@ApiResponse(responseCode = "200",description = "成功")})
@Api(value = "测试类")
@RestController
@RequestMapping("/swagger")
public class SwaggerController{

    @Operation(summary = "获取Swagger")
    @GetMapping("/getSwagger")
    public String getSwagger(){
        return "hello swagger";
    }

    @Operation(summary = "带有参数的Swagger")
    @PostMapping("/getParam")
    public String getParam(@Parameter(description = "用户名")  @RequestParam String username){
        return username;
    }

    @Operation(summary = "modal的用户")
    @PostMapping("editSwager")
    @ApiResponses({@ApiResponse(responseCode = "0",description = "参数或者DB错误"),
            @ApiResponse(responseCode = "1",description = "成功"),
            @ApiResponse(responseCode = "2",description = "没有登录")})
    public ResponseData<User> editSwagger(@RequestBody User user){
        ResponseData<User> responseData;
        if (user.getUsername().equals("hett")){
            responseData = ResponseData.success(user);
        }
        else {
            responseData = ResponseData.error(EnumCode.NOT_LOGIN);
        }
        return responseData;
    }

}
